var express = require('express');
var router = express.Router();
var projectModel = require('../db/project');
/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});

//获取project列表，支持时间区间筛选
router.get('/getProjects', async function(req, res, next) {
  const { start, end } = req.query;
  let query = {};
  if (start && end) {
    // 假设你的项目开始时间字段为 projectStartDate，格式为 'YYYY-MM-DD' 或 'YYYY-MM-DD HH:mm'
    query.projectStartDate = { $gte: start, $lte: end };
  }
  try {
    const result = await projectModel.find(query);
    res.json({
      code: 200,
      msg: "success",
      data: result
    });
  } catch (err) {
    res.json({
      code: 500,
      msg: "数据库查询失败",
      data: []
    });
  }
});

module.exports = router;